/**
 * Created by ptt on 2016/5/27/0027.
 */
define(["./dataHandle.js", "./tpl.js", "../maintools/Controller.js", "../popup/listener.js"], function (handle, tpl, Controller, popup) {
    //initial searchbox has bug for global value jQuery
    Controller = Controller.Controller;
    tpl = tpl.nav;
    popup = popup.popupController;
    $("#navigation").html(tpl.render());

    var toggleClass = Controller.create({
        events: {
            "click div.js-statistical": "changeState",
            "click div.js-tools": "changeState"
        },
        elements: {
            "div.js-statistical": "divStat",
            "div.js-tools": "divTools"
        },
        changeColor: function (e) {
            var div = $(e.currentTarget);
            div.toggleClass("click");
            div[0] === this.divStat[0] ? popup.toggle() : popup.hide();
        },
        changeState: function (e) {
            for (var key in this.elements) {
                e.currentTarget === this[this.elements[key]][0] ? this.changeColor(e) : this[this.elements[key]].removeClass("click");
            }
        }
    });
    var triggerClick = new toggleClass("#navigation");
    return {
        navigationController: triggerClick
    };
});